package com.esri.core.internal.tasks.f;

import com.esri.core.internal.util.d;
import com.esri.core.map.FeatureResult;
import com.esri.core.map.Field;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.JsonToken;

/* loaded from: classes.dex */
public class c {
    public static FeatureResult a(String str) throws Exception {
        return a(d.c(str));
    }

    public static FeatureResult a(JsonParser jsonParser) throws Exception {
        if (d.c(jsonParser)) {
            ArrayList arrayList = new ArrayList();
            ArrayList arrayList2 = new ArrayList();
            boolean z = false;
            while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
                try {
                    String currentName = jsonParser.getCurrentName();
                    jsonParser.nextToken();
                    if ("fields".equals(currentName)) {
                        if (jsonParser.getCurrentToken() == JsonToken.START_ARRAY) {
                            while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
                                arrayList.add(Field.fromJson(jsonParser));
                            }
                        }
                    } else if ("features".equals(currentName)) {
                        if (jsonParser.getCurrentToken() == JsonToken.START_ARRAY) {
                            while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
                                while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
                                    String currentName2 = jsonParser.getCurrentName();
                                    jsonParser.nextToken();
                                    if ("attributes".equals(currentName2)) {
                                        LinkedHashMap linkedHashMap = new LinkedHashMap();
                                        d.a(jsonParser, linkedHashMap);
                                        arrayList2.add(linkedHashMap);
                                    } else {
                                        jsonParser.skipChildren();
                                    }
                                }
                            }
                        }
                    } else if ("exceededTransferLimit".equals(currentName)) {
                        z = jsonParser.getBooleanValue();
                    } else {
                        jsonParser.skipChildren();
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            return new a(arrayList2, arrayList, z);
        }
        return null;
    }

    public static void a(ArrayList<com.esri.core.internal.tasks.ags.c.a> arrayList, List<Field> list) {
        if (arrayList == null || arrayList.size() < 1 || list == null) {
            return;
        }
        for (Field field : list) {
            if (field.getFieldType() == 30) {
                String name = field.getName();
                Iterator<com.esri.core.internal.tasks.ags.c.a> it = arrayList.iterator();
                while (it.hasNext()) {
                    com.esri.core.internal.tasks.ags.c.a next = it.next();
                    Object attributeValue = next.getAttributeValue(name);
                    if (attributeValue != null && !(attributeValue instanceof Double)) {
                        next.getAttributes().put(name, new Double(attributeValue.toString()));
                    }
                }
            } else if (field.getFieldType() == 50) {
                String name2 = field.getName();
                Iterator<com.esri.core.internal.tasks.ags.c.a> it2 = arrayList.iterator();
                while (it2.hasNext()) {
                    com.esri.core.internal.tasks.ags.c.a next2 = it2.next();
                    Object attributeValue2 = next2.getAttributeValue(name2);
                    if (attributeValue2 != null && (attributeValue2 instanceof Integer)) {
                        next2.getAttributes().put(name2, new Long(attributeValue2.toString()));
                    }
                }
            }
        }
    }
}
